from flask_socketio import emit
from flask_socketio import join_room, leave_room

from cyoa import socketio
from cyoa.views import broadcast_vote_count

@socketio.on('connect', namespace='/cyoa')
def ws_connect():
    print("ws_connect")

@socketio.on('disconnect', namespace='/cyoa')
def ws_disconnect():
    print("ws_disconnect")


@socketio.on('join', namespace='/cyoa')
def on_join(data):
    vote = data['vote']
    join_room(vote)
    broadcast_vote_count(vote)

